<template>
	<view>
		<cu-custom bgColor="bg-gradual-green" :isBack="true">
			<block slot="content">我的钱包</block>
		</cu-custom>

		<view class="cu-card dynamic">
			<view class="cu-item shadow">
				<view class="cu-list menu-avatar padding">
					<text class="text-center text-xsl text-bold text-yellow">￥{{money}}</text>
				</view>
			</view>
		</view>

		<view class="cu-list menu sm-border card-menu" @click="onCash">
			<view class="cu-item arrow">
				<view class="content">
					<text class="text-grey">提现</text>
				</view>
			</view>
		</view>

		<view class="cu-modal bottom-modal" :class=" showModal ? 'show' : '' ">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">
					<view class="action text-blue" @click="hideModal">取消</view>
					<view class="action text-green" @click="onSubmit">确定</view>
				</view>
				<view class="padding">
					<view class="padding">
						<input type="digit" v-model="inputVal" style="height:80rpx;line-height: 80rpx;" placeholder="输入提现金额" class="bg-white">
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'

	export default {
		data() {
			return {
				showModal: false,
				inputVal: '',
				money: 0
			}
		},
		onShow() {
			this.getMoneyList();
		},
		onHide() {},
		onLoad() {

		},
		methods: {
			getMoneyList() {
				this.$http.post('getMoneyList').then(res => {
					console.log(res)
					this.money = res.data.remain ? res.data.remain : 0;
				})
			},
			onCash() {
				console.log(1)
				this.showModal = true;
				console.log(this.showModal)
			},
			hideModal() {
				this.showModal = false;
			},
			onSubmit() {
				if (this.money * 1 <= this.inputVal * 1) {
					uni.showToast({
						title: '提现金额不能比余额少',
						icon: 'none'
					})
					return;
				}
				this.$http.post('donate', {
					price: this.inputVal * 1
				}).then(res => {
					if (res.code == 1) {
						this.getMoneyList();
						this.showModal = false;
						uni.showToast({
							title: '成功',
							position: '24小时内到账'
						})
					}
					console.log(res)
				})

			}
		}
	}
</script>

<style>

</style>
